/*store用户管理部分*/
import http from '../../../tool/http'
import api from '../../../tool/api'

export default {
    state: {//状态
        userData: [],
    },
    mutations: {//（修改/操作）状态
        //获取userData的值
        getUserData(state, {arr, roleDataArr}) {
            /*arr数据加工*/
            arr.map(outItem => {
                /*roleDesc调整*/
                if (!outItem.backUserEmail) outItem.backUserEmail = '暂无信息';
                if (!outItem.backUserTel) outItem.backUserTel = '暂无信息';
                if (!outItem.backUserPassword) outItem.backUserPassword = '';
                if (!outItem.roleName) {
                    outItem.roleId = '';
                    outItem.roleName = '暂无信息';
                } else {
                    roleDataArr.map(r => {
                        if (outItem.roleName === r.roleName) {
                            outItem.roleName = r.roleName;
                            outItem.roleId = r.roleId;
                        }
                    })
                }
                /*roleStatus调整*/
                outItem.backUserStatus === 1 ? outItem.backUserStatus = '正常' : outItem.backUserStatus = '禁用';
            });
            /*为userData状态变量赋值*/
            state.userData = [...arr]
            //console.log(state.userData);
        },
    },
    actions: {//1.异步执行（修改/操作）状态  2.异步执行mutations里面的方法
        getUserDataAction({commit}, roleDataArr) {
            return http({
                url: api.getManagerMsg + '?page=1&pageSize=1000',
                method: 'get'
            }).then(res => {
                //console.log(res);
                if (res.data.code === 200) {
                    //console.log(res.data.data);
                    commit('getUserData', {arr: res.data.data, roleDataArr})
                }
            }).catch(err => console.log(err))
        },
    },
    getters: {//加工状态，并传递给外界
        userData(state) {
            return state.userData
        },
    }
}
